package com.example.demo.sort;

/**
 * 冒泡排序
 */
public class BubbleSort {


    public static void sort(int[] arr) {

        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = {9, 6, 8, 1, 4, 2, 3};
        sort(arr);
        for (int val : arr) {
            System.out.println(val);
        }

    }


}
